package io.renren.sf.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.sf.entity.CbStiffCalligraphyPictureEntity;
import io.renren.sf.service.CbStiffCalligraphyPictureService;
import io.renren.sf.vo.CbStiffCalligraphyListVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.sf.entity.CbStiffCalligraphyEntity;
import io.renren.sf.service.CbStiffCalligraphyService;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author cyl_txw
 * @email cyl_txw@gmail.com
 * @date 2021-04-26 10:46:38
 */
@RestController
@RequestMapping("sf/cbstiffcalligraphy")
public class CbStiffCalligraphyController {
    @Autowired
    private CbStiffCalligraphyService cbStiffCalligraphyService;

    @Autowired
    private CbStiffCalligraphyPictureService cbStiffCalligraphyPictureService;

    /**
     * 根据类型获取书法基础List
     */
    @PostMapping("/getInfoList")
    //@RequiresPermissions("sf:cbstiffcalligraphy:info")
    public R info(@RequestBody CbStiffCalligraphyListVo cbStiffCalligraphyListVo){
        List<CbStiffCalligraphyEntity> calligraphyList = cbStiffCalligraphyService.list(new QueryWrapper<CbStiffCalligraphyEntity>().eq("type", cbStiffCalligraphyListVo.getType()).orderByAsc("corder"));
        for (CbStiffCalligraphyEntity calligraphyEntity : calligraphyList){
            List<CbStiffCalligraphyPictureEntity> calligraphyPictureList = cbStiffCalligraphyPictureService.list(new QueryWrapper<CbStiffCalligraphyPictureEntity>().eq("cid", calligraphyEntity.getId()));
            calligraphyEntity.setCalligraphyPictures(calligraphyPictureList);
        }
        return R.ok().put("calligraphyList", calligraphyList);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("sf:cbstiffcalligraphy:info")
    public R info(@PathVariable("id") Long id){
		CbStiffCalligraphyEntity cbStiffCalligraphy = cbStiffCalligraphyService.getById(id);

        return R.ok().put("cbStiffCalligraphy", cbStiffCalligraphy);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("sf:cbstiffcalligraphy:save")
    public R save(@RequestBody CbStiffCalligraphyEntity cbStiffCalligraphy){
		cbStiffCalligraphyService.save(cbStiffCalligraphy);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@RequiresPermissions("sf:cbstiffcalligraphy:update")
    public R update(@RequestBody CbStiffCalligraphyEntity cbStiffCalligraphy){
		cbStiffCalligraphyService.updateById(cbStiffCalligraphy);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    //@RequiresPermissions("sf:cbstiffcalligraphy:delete")
    public R delete(@RequestBody Long[] ids){
		cbStiffCalligraphyService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
